<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/vue/2.6.14/vue.js" type="application/javascript"></script>
</head>
<body>
  <div id="app">
    <!-- v-on:事件名,如何作用于组件,"它是父子通信当中,父组件监听子组件的消息" -->
    <!-- 注意:这里的click它是事件名,可以为任意名,恰好它是click -->
    <!-- 监听子组件消息-方式1-通过父子通信 -->
    <!-- <el-button @click="onClick"></el-button> -->
    <!-- 监听子组件消息-方式2.1-通过原生事件的冒泡 -->
    <!-- <div @click="onClick">
      <el-button></el-button>
    </div> -->
     <!-- 监听子组件消息-方式2.2-通过原生事件的冒泡,用到语法糖 -->
     <!-- 什么是语法糖?甜,为了方便写法,但是没有改变原理, 例如promise和异步函数 -->
    <el-button @click.native="onClick"></el-button>
  </div>
</body>
<script>
  /*
  Vue.component('el-button', {
    template: `
      <button @click="$emit('click')">按钮</button>
    `
  })
  */
  Vue.component('el-button', {
    template: `
      <button>按钮</button>
    `
  })
  let vm = new Vue({
    el: '#app',
    data(){
      return {
        msg: 'hello'
      }
    },
    methods: {
      onClick(){
        console.log('点击了')
      }
    }
  })
</script>
</html>
